<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>管理员管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"><!-- 确保适当的绘制和触屏缩放 -->
    <link rel="stylesheet" href="{$url_css}bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="{$url_css}admin.css" type="text/css">

    <script type="text/javascript" src="{$url_js}jquery-1.12.0.min.js"></script>
</head>
<body>
    <div class="container" style="width:96%">
        <table class="table table-bordered table-striped" align="center" id="list">
            <tr><td colspan="6">添加管理员</td></tr>
            <tr>
                <td class="col-xs-1 vc">搜索</td>
                <td class="form-group col-xs-2" colspan="2">
                    <div class="input-group" style="width: 100%">
                        <div class="input-group-addon">用户ID 或 邮箱</div>
                        <input type="text" class="form-control" id="user_search_key" placeholder=""/>
                    </div>
                </td>
                <td class="col-xs-8" colspan=""><button class="btn btn-default search_user">搜索</button></td>
            </tr>
            <tr>
                <td class="col-xs-1 vc">搜索结果</td>
                <td class="form-group col-xs-2">
                    <div class="input-group">
                        <div class="input-group-addon">用户ID</div>
                        <input type="text" class="form-control" id="user_id" placeholder="" readonly >
                    </div>
                </td>
                <td class="form-group col-xs-2">
                    <div class="input-group">
                        <div class="input-group-addon">用户名</div>
                        <input type="text" class="form-control" id="user_name" placeholder="" readonly >
                    </div>
                </td>
                <td class="col-xs-7">&nbsp;</td>
            </tr>
            <tr>
                <td class="col-xs-1 vc">操作</td>
                <td class="col-xs-2 form-group">
                    <div class="input-group">
                        <div class="input-group-addon">管理组</div>
                        <select id="auth-group" class="form-control">
                            {$groupselect}
                        </select>
                    </div>
                </td>
                <td class="form-group col-xs-2">
                    <div class="input-group">
                        <div class="input-group-addon">姓名</div>
                        <input type="text" class="form-control" id="true_name" placeholder="">
                    </div>
                </td>
                <td class="col-xs-6" colspan="2"><button class="btn btn-default add-admin">设为管理员</button></td>
            </tr>
        </table>

        <div class="page-header">
              <h3>管理员列表</h3>
        </div>
        <table class="table table-bordered table-striped" align="center">
            <tr>
                <td>用户ID</td>
                <td>管理组</td>
                <td>真实姓名</td>
                <td>操作</td>
            </tr>
            {foreach $user as $v}
                <tr>
                    <td class="col-xs-1">{$v.AdminUserId}</td>
                    <td class="col-xs-2">{$v.GroupData.GroupName}</td>
                    <td class="col-xs-2">{$v.AdminUserName}</td>
                    <td>
                        <div class="btn-group btn-group-sm" role="group" aria-label="..." style="width:100px">
                            <a href="user.php?do=edit&userid={$v.AdminUserId}" class="btn btn-default">编辑</a>
                            <a class="btn btn-danger delete" href="?do=del&userid={$v.AdminUserId}">删除</a>
                        </div>
                    </td>
                </tr>
            {/foreach}

            {if $pagination != ''}
                <tr><td colspan="4">{$pagination}</td></tr>
            {/if}
        </table>

    </div>

    <script type="text/javascript">
        {literal}
            $(".delete").click(function(){
                var url = self.location.pathname + $(this).attr("href");
                top.__confirm('确定要删除吗？','删除后不可恢复！', url, self);
                return false;
            });

            $(".search_user").click(function(){
                if ($('#user_search_key').val() != ''){
                    $.ajax({
                        url:'user.php?do=searchuser',
                        data:{key:$('#user_search_key').val()},
                        dataType:'json',
                        success:function(re){
                            if (re.length == 0){
                                $("#user_id").val('');
                                $("#user_name").val('');
                                top.swal('出错了','用户不存在','warning');
                            }else{
                                $("#user_id").val(re.UserId);
                                $("#user_name").val(re.UserName);
                            }
                        }
                    });
                }else{
                    top.swal('出错了','搜索条件不能为空','warning');
                }
            });

            $(".add-admin").click(function(){
                var userid = $('#user_id').val();
                var true_name = $("#true_name").val();
                var groupid = $("#auth-group").val();
                if (userid == ''){
                    top.swal('出错了','请先选择用户','error');
                }else{
                    $.ajax({
                        url:'user.php?do=addadmin',
                        type:"post",
                        data:{userid:userid,true_name:true_name,groupid:groupid},
                        dataType:"json",
                        success:function(re){
                            top.swal(re);
                            if(re.type == 'success'){
                                self.location.reload();
                            }
                        }
                    })
                }
            })
        {/literal}
    </script>
</body>
<html>
    